<?php
require("include/top.php");

if (!empty($_SESSION['vendor']['id'])) {
	if ((isset($_POST['sold']))||(isset($_POST['class']))) {
		require(FORM_PATH."sold_products.form.php");
	}
	$tpl->display("header.tpl");
	$tpl->display("menu.tpl");
			if(!empty($_SESSION['vendor'])){
				
				if(!empty($_POST['class'])) {
				
					if($_POST['classer']==1) {
	
						$products=$_SESSION['vendor']->getProductsAll();
						if(!empty($products)){
						$tpl->assign ('products',$products);
						$tpl->assign('select',1);
						}
					}
					if($_POST['classer']==2) {
	
						$products=$_SESSION['vendor']->getProductsReduc();
						if(!empty($products)){
						$tpl->assign ('products',$products);
						$tpl->assign('select',2);
						}
					}
						if($_POST['classer']==3) {
	
							$products=$_SESSION['vendor']->getSmallStock();
							if(!empty($products)){
							$tpl->assign ('products',$products);
							$tpl->assign('select',3);
						}
					}
					
					
						if($_POST['classer']==4) {
	
							$products=$_SESSION['vendor']->getMostSolded();
							if(!empty($products)){
							$tpl->assign ('products',$products);
							$tpl->assign('select',4);
						}
					}
					
						if($_POST['classer']==5) {
	
							$products=$_SESSION['vendor']->getMostSeen();
							if(!empty($products)){
							$tpl->assign ('products',$products);
							$tpl->assign('select',5);
						}
					}
						if($_POST['classer']==6) {
	
							$products=$_SESSION['vendor']->getMostWL();
							if(!empty($products)){
							$tpl->assign ('products',$products);
							$tpl->assign('select',6);
						}
					}
					if($_POST['classer']==7) {
	
							$products=$_SESSION['vendor']->getProductsOnline();
							if(!empty($products)){
							$tpl->assign ('products',$products);
							$tpl->assign('select',7);
						}
					}
					if($_POST['classer']==8) {
	
							$products=$_SESSION['vendor']->getProductsOffline();
							if(!empty($products)){
							$tpl->assign ('products',$products);
							$tpl->assign('select',8);
						}
					}
				}
				elseif(!empty($_POST['search'])) {
					$results=Search::searchProducts($_POST['keyword']);
					foreach($results as $product) {
						if($product['vendor']['id']==$_SESSION['vendor']['id']) {
						$products[]=$product;
						
						}
					}
					$tpl->assign ('products',$products);
					$tpl->assign('select',1);
				}
	
				else {
				
				$products= $_SESSION['vendor']->getProductsAll();
				$tpl->assign ('products',$products);
				$tpl->assign('select',1);
				}
				
				
				
				
				$tpl->display("sold_products.tpl");
				}
	$tpl->display("footer.tpl");
}
else{header('Location:login.php');}
	
require("include/bottom.php");	
?>